package com.ymatou.iapi.couponmanage.testcase;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.couponmanage.parameter.BagInfo;
import com.ymatou.iapi.couponmanage.parameter.CreateBagBean;
import com.ymatou.iapi.couponmanage.parameter.CreateBean;
import com.ymatou.iapi.couponmanage.parameter.GetBagsByPaging;
import com.ymatou.iapi.couponmanage.parameter.executeTaskBean;
import com.ymatou.iapi.couponmanage.parameter.queryBagBean;
import com.ymatou.iapi.couponmanage.service.CreateBagCall;
import com.ymatou.iapi.couponmanage.service.CreateCall;
import com.ymatou.iapi.couponmanage.service.executeTaskCall;
import com.ymatou.iapi.couponmanage.service.queryBagCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponServiceMCallServiceV2;
import com.ymttest.database.model.couponbag;
import com.ymttest.database.model.couponbatch;
import com.ymttest.database.model.couponconversion;
import com.ymttest.database.model.couponconversionbatch;
import com.ymttest.database.model.couponconversioncode;
import com.ymttest.database.sqlwapper.couponWapper;
import com.ymttest.database.sqlwapper.couponbagWapper;
import com.ymttest.database.sqlwapper.couponbatchWapper;
import com.ymttest.database.sqlwapper.couponconversionWapper;
import com.ymttest.database.sqlwapper.couponconversionbatchWapper;
import com.ymttest.database.sqlwapper.couponconversioncodeWapper;
import com.ymttest.database.sqlwapper.couponsendsubtaskWapper;
/**
*作废套券
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_queryBag{
	private static queryBagBean querybagBean;
	private static queryBagCall querybagCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("作废套券");
	}

	@Before
	public void caseUp() {
		querybagBean=new queryBagBean();
		querybagCall=new queryBagCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(querybagCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_031() {
		Logger.start(true,"分页获取套券-验证领取方式:acquireMethod=-1不限");
		try {
			setDefaultPlatformQueryBag();
			Thread.sleep(1000);
			querybagBean.setAcquireMethod(-1);
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			verifyReturn();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_001() {
		Logger.start(true,"分页获取套券-验证领取方式:acquireMethod=1直接领取");
		try {
			setDefaultPlatformQueryBag();
			Thread.sleep(1000);
			querybagBean.setAcquireMethod(1);
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			verifyReturn();	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_002() {
		Logger.start(true,"分页获取套券-验证领取方式:acquireMethod=2兑换");
		try {
			setDefaultPlatformQueryBag();
			querybagBean.setAcquireMethod(2);
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			verifyReturn();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_032() {
		Logger.start(true,"分页获取套券-验证有效期类型:effectiveType=-1不限");
		try {
			setDefaultPlatformQueryBag();
			querybagBean.setEffectiveType(-1);
			Thread.sleep(1000);
			querybagBean.setAcquireMethod(1);
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			verifyReturn();	

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_012() {
		Logger.start(true,"分页获取套券-验证有效期类型:effectiveType=0绝对");
		try {
			setDefaultPlatformQueryBag();
			querybagBean.setEffectiveType(0);
			Thread.sleep(1000);
			querybagBean.setAcquireMethod(1);
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			verifyReturn();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_013() {
		Logger.start(true,"分页获取套券-验证有效期类型:effectiveType=1相对");
		try {
			setDefaultPlatformQueryBag();
			querybagBean.setEffectiveType(1);
			Thread.sleep(1000);
			querybagBean.setAcquireMethod(1);
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			verifyReturn();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_014() {
		Logger.start(false,"分页获取套券-验证时间:createTimeStart>createTimeEnd");
		try {
			setDefaultPlatformQueryBag();
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, 1); // 设置为后2天
	        dAfter = calendar2.getTime(); // 得到后2天的时间
	        
	        querybagBean.setCreateTimeStart(dAfter);
	        querybagBean.setCreateTimeEnd(dBefore);
			Thread.sleep(1000);
			querybagBean.setAcquireMethod(1);
			querybagCall.setData(querybagBean);
			querybagCall.callService();	
			
			Logger.verifyEquals("0", querybagCall.getStatusCode1(), "验证返回code");
	        Logger.verifyEquals("操作成功！", querybagCall.getMessage(), "验证返回Message");
	      
	        GetBagsByPaging bagsByPaging=querybagCall.getBagInfosReturnData();
	        List<BagInfo> bagInfos=bagsByPaging.getBagInfos();
	        Logger.verifyEquals(0, bagsByPaging.getRecordCount(), "验证返回recordCount=0");
	        Logger.verifyEquals(0, bagInfos.size(), "验证返回bagInfos总条数为0");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_015() {
		Logger.start(true,"分页获取套券-验证页码:总数大于当前页数量");
		try {
			
			setDefaultPlatformQueryBag();
			Thread.sleep(1000);
			CouponServiceMCallServiceV2 CouponServiceMCallServiceV2 = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = CouponServiceMCallServiceV2.setDefaultPlatformCreateCouponBagBeanForRecieve();
			CreateBagCall createBagCall = CouponServiceMCallServiceV2.createPlatformCouponBag(createBagBean);
			querybagBean.setBagCode(null);
			querybagBean.setPageIndex(1);
			querybagBean.setPageSize(1);
			Thread.sleep(1000);
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			verifyReturn();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_016() {
		Logger.start(true,"分页获取套券-验证页码:pageIndex=-1当前页码小于0");
		try {
			setDefaultPlatformQueryBag();
			Thread.sleep(1000);
			querybagBean.setPageIndex(-1);
			querybagBean.setPageSize(1);
			Thread.sleep(1000);
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			Logger.verifyEquals("1", querybagCall.getStatusCode1(), "验证返回code");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_017() {
		Logger.start(true,"分页获取套券-验证页码:pageIndex=0当前页码等于0");
		try {
			setDefaultPlatformQueryBag();
			Thread.sleep(1000);
			querybagBean.setPageIndex(0);
			querybagBean.setPageSize(1);
			Thread.sleep(1000);
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			Logger.verifyEquals("1", querybagCall.getStatusCode1(), "验证返回code");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_018() {
		Logger.start(true,"分页获取套券-验证每页记录数:pageSize=-1没有记录数小于0");
		try {
			setDefaultPlatformQueryBag();
			Thread.sleep(1000);
			querybagBean.setPageIndex(1);
			querybagBean.setPageSize(-1);
			Thread.sleep(1000);
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			Logger.verifyEquals("1", querybagCall.getStatusCode1(), "验证返回code");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_019() {
		Logger.start(true,"分页获取套券-验证每页记录数:pageSize=0没有记录数等于于0");
		try {
			setDefaultPlatformQueryBag();
			Thread.sleep(1000);
			querybagBean.setPageIndex(1);
			querybagBean.setPageSize(0);
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			Logger.verifyEquals("1", querybagCall.getStatusCode1(), "验证返回code");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_020() {
		Logger.start(true,"分页获取套券-验证领取方式:acquireMethod=2兑换(自定义兑换码)");
		try {
			CouponServiceMCallServiceV2 mCouponserviceCallService = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = mCouponserviceCallService.setDefaultPlatformCreateCouponBagBeanForRecieve();
			createBagBean.setAcquireMethod(2);//领取方式是套券
			CreateBagCall createBagCall = mCouponserviceCallService.createPlatformCouponBag(createBagBean);
			
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, 1); // 设置为后2天
	        dAfter = calendar2.getTime(); // 得到后2天的时间
	        
			querybagBean.setBagCode(createBagCall.getbagCode());
			querybagBean.setConversionCode(null);
			querybagBean.setAcquireMethod(2);
			querybagBean.setEffectiveType(0);//有效期类型 0:绝对  1:相对
			querybagBean.setCreateTimeStart(dBefore);
			querybagBean.setCreateTimeEnd(dAfter);
			querybagBean.setApplyDepartment(1);
			querybagBean.setPageIndex(1);
			querybagBean.setPageSize(10);

			 //生成批次及兑换码
			List<String> bagCodes = new ArrayList<>();
			bagCodes.add(createBagCall.getbagCode());

			CreateBean createBean = mCouponserviceCallService.setDefaultCustomCreateBean(bagCodes);
			createBean.setBatchType(2);
			CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			verifyReturn();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_033() {
		Logger.start(true,"分页获取套券-验证领取方式:acquireMethod=2兑换(随机兑换码)");
		try {
			CouponServiceMCallServiceV2 mCouponserviceCallService = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = mCouponserviceCallService.setDefaultPlatformCreateCouponBagBeanForRecieve();
			createBagBean.setAcquireMethod(2);//领取方式是套券
			CreateBagCall createBagCall = mCouponserviceCallService.createPlatformCouponBag(createBagBean);
			
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, 1); // 设置为后2天
	        dAfter = calendar2.getTime(); // 得到后2天的时间
	        
			querybagBean.setBagCode(createBagCall.getbagCode());
			querybagBean.setConversionCode(null);
			querybagBean.setAcquireMethod(2);
			querybagBean.setEffectiveType(0);//有效期类型 0:绝对  1:相对
			querybagBean.setCreateTimeStart(dBefore);
			querybagBean.setCreateTimeEnd(dAfter);
			querybagBean.setApplyDepartment(1);
			querybagBean.setPageIndex(1);
			querybagBean.setPageSize(10);

			 //生成批次及兑换码
				List<String> bagCodes = new ArrayList<>();
				bagCodes.add(createBagCall.getbagCode());

				CreateBean createBean = mCouponserviceCallService.setDefaultRandomCreateBean(bagCodes);
				createBean.setBatchType(2);
				CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			

			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			verifyReturn();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_021() {
		Logger.start(true,"分页获取套券-验证套券编码不存在");
		try {
			setDefaultPlatformQueryBag();
			Thread.sleep(1000);
			querybagBean.setBagCode("999999999999999");
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			
			Logger.verifyEquals("0", querybagCall.getStatusCode1(), "验证返回code");
	        Logger.verifyEquals("操作成功！", querybagCall.getMessage(), "验证返回Message");
	      
	        GetBagsByPaging bagsByPaging=querybagCall.getBagInfosReturnData();
	        List<BagInfo> bagInfos=bagsByPaging.getBagInfos();
	        Logger.verifyEquals(0, bagsByPaging.getRecordCount(), "验证返回recordCount=0");
	        Logger.verifyEquals(0, bagInfos.size(), "验证返回bagInfos总条数为0");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_022() {
		Logger.start(true,"分页获取套券-验证套券编码为空");
		try {
			setDefaultPlatformQueryBag();
			Thread.sleep(1000);
			querybagBean.setBagCode(null);
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			verifyReturn();	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_023() {
		Logger.start(true,"分页获取套券-验证兑换码不存在");
		try {
			setDefaultPlatformQueryBag();
			Thread.sleep(1000);
			querybagBean.setConversionCode("999999999999");
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			Logger.verifyEquals("0", querybagCall.getStatusCode1(), "验证返回code");
	        Logger.verifyEquals("操作成功！", querybagCall.getMessage(), "验证返回Message");
	      
	        GetBagsByPaging bagsByPaging=querybagCall.getBagInfosReturnData();
	        List<BagInfo> bagInfos=bagsByPaging.getBagInfos();
	        Logger.verifyEquals(0, bagsByPaging.getRecordCount(), "验证返回recordCount=0");
	        Logger.verifyEquals(0, bagInfos.size(), "验证返回bagInfos总条数为0");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_024() {
		Logger.start(true,"分页获取套券-验证兑换码为空");
		try {
			setDefaultPlatformQueryBag();
			Thread.sleep(1000);
			querybagBean.setConversionCode(null);
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			verifyReturn();				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_025() {
		Logger.start(true,"分页获取套券-验证申请部门为空");
		try {
			setDefaultPlatformQueryBag();
			Thread.sleep(1000);
			querybagBean.setApplyDepartment(0);
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			Logger.verifyEquals("0", querybagCall.getStatusCode1(), "验证返回code");
	        Logger.verifyEquals("操作成功！", querybagCall.getMessage(), "验证返回Message");
	      
	        GetBagsByPaging bagsByPaging=querybagCall.getBagInfosReturnData();
	        List<BagInfo> bagInfos=bagsByPaging.getBagInfos();
	        Logger.verifyEquals(0, bagsByPaging.getRecordCount(), "验证返回recordCount=0");
	        Logger.verifyEquals(0, bagInfos.size(), "验证返回bagInfos总条数为0");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_026() {
		Logger.start(true,"分页获取套券-验证申请部门:applyDepartment=-1不限");
		try {
			setDefaultPlatformQueryBag();
			Thread.sleep(1000);
			querybagBean.setApplyDepartment(-1);
			querybagCall.setData(querybagBean);
			querybagCall.callService();					
			verifyReturn();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_027() {
		Logger.start(true,"分页获取套券-验证申请部门:applyDepartment=1市场");
		try {
			CouponServiceMCallServiceV2 CouponServiceMCallServiceV2 = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = CouponServiceMCallServiceV2.setDefaultPlatformCreateCouponBagBeanForRecieve();
			createBagBean.setApplyDepartment(1);
			CreateBagCall createBagCall = CouponServiceMCallServiceV2.createPlatformCouponBag(createBagBean);
			
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, 1); // 设置为后2天
	        dAfter = calendar2.getTime(); // 得到后2天的时间
	        Thread.sleep(1000);
	        
			querybagBean.setBagCode(createBagCall.getbagCode());
			querybagBean.setConversionCode(null);
			querybagBean.setAcquireMethod(1);
			//querybagBean.setLimitType(1);
			querybagBean.setEffectiveType(0);//有效期类型 0:绝对  1:相对
			querybagBean.setCreateTimeStart(dBefore);
			querybagBean.setCreateTimeEnd(dAfter);
			querybagBean.setApplyDepartment(1);
			querybagBean.setPageIndex(1);
			querybagBean.setPageSize(10);
			querybagCall.setData(querybagBean);
			querybagCall.callService();					
			verifyReturn();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_028() {
		Logger.start(true,"分页获取套券-验证申请部门:applyDepartment=2运营");
		try {
			CouponServiceMCallServiceV2 CouponServiceMCallServiceV2 = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = CouponServiceMCallServiceV2.setDefaultPlatformCreateCouponBagBeanForRecieve();
			createBagBean.setApplyDepartment(2);
			CreateBagCall createBagCall = CouponServiceMCallServiceV2.createPlatformCouponBag(createBagBean);
			
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, 1); // 设置为后2天
	        dAfter = calendar2.getTime(); // 得到后2天的时间
	        Thread.sleep(1000);
	        
			querybagBean.setBagCode(createBagCall.getbagCode());
			querybagBean.setConversionCode(null);
			querybagBean.setAcquireMethod(1);
			//querybagBean.setLimitType(1);
			querybagBean.setEffectiveType(0);//有效期类型 0:绝对  1:相对
			querybagBean.setCreateTimeStart(dBefore);
			querybagBean.setCreateTimeEnd(dAfter);
			querybagBean.setApplyDepartment(2);
			querybagBean.setPageIndex(1);
			querybagBean.setPageSize(10);
			querybagCall.setData(querybagBean);
			querybagCall.callService();					
			verifyReturn();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_029() {
		Logger.start(true,"分页获取套券-验证申请部门:applyDepartment=3客服");
		try {
			CouponServiceMCallServiceV2 CouponServiceMCallServiceV2 = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = CouponServiceMCallServiceV2.setDefaultPlatformCreateCouponBagBeanForRecieve();
			createBagBean.setApplyDepartment(3);
			CreateBagCall createBagCall = CouponServiceMCallServiceV2.createPlatformCouponBag(createBagBean);
			
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, 1); // 设置为后2天
	        dAfter = calendar2.getTime(); // 得到后2天的时间
	        Thread.sleep(1000);
			querybagBean.setBagCode(createBagCall.getbagCode());
			querybagBean.setConversionCode(null);
			querybagBean.setAcquireMethod(1);
			querybagBean.setEffectiveType(0);//有效期类型 0:绝对  1:相对
			querybagBean.setCreateTimeStart(dBefore);
			querybagBean.setCreateTimeEnd(dAfter);
			querybagBean.setApplyDepartment(3);
			querybagBean.setPageIndex(1);
			querybagBean.setPageSize(10);
			querybagCall.setData(querybagBean);
			querybagCall.callService();					
			verifyReturn();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_030() {
		Logger.start(true,"分页获取套券-验证申请部门:applyDepartment=4研发");
		try {
			CouponServiceMCallServiceV2 CouponServiceMCallServiceV2 = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = CouponServiceMCallServiceV2.setDefaultPlatformCreateCouponBagBeanForRecieve();
			createBagBean.setApplyDepartment(4);
			CreateBagCall createBagCall = CouponServiceMCallServiceV2.createPlatformCouponBag(createBagBean);
			
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, 1); // 设置为后2天
	        dAfter = calendar2.getTime(); // 得到后2天的时间
	        Thread.sleep(1000);
			querybagBean.setBagCode(createBagCall.getbagCode());
			querybagBean.setConversionCode(null);
			querybagBean.setAcquireMethod(1);
			querybagBean.setEffectiveType(0);//有效期类型 0:绝对  1:相对
			querybagBean.setCreateTimeStart(dBefore);
			querybagBean.setCreateTimeEnd(dAfter);
			querybagBean.setApplyDepartment(4);
			querybagBean.setPageIndex(1);
			querybagBean.setPageSize(10);
			querybagCall.setData(querybagBean);
			querybagCall.callService();					
			verifyReturn();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_queryBag_034() {
		Logger.start(true,"分页获取套券-验证conversionCode:conversionCode不为空(随机兑换码)");
		try {
			CouponServiceMCallServiceV2 mCouponserviceCallService = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = mCouponserviceCallService.setDefaultPlatformCreateCouponBagBeanForRecieve();
			createBagBean.setAcquireMethod(2);//领取方式是套券
			CreateBagCall createBagCall = mCouponserviceCallService.createPlatformCouponBag(createBagBean);
			
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, 1); // 设置为后2天
	        dAfter = calendar2.getTime(); // 得到后2天的时间

			 //生成批次及兑换码
			List<String> bagCodes = new ArrayList<>();
			bagCodes.add(createBagCall.getbagCode());

			CreateBean createBean = mCouponserviceCallService.setDefaultRandomCreateBean(bagCodes);
			createBean.setBatchType(2);
			CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			
            couponconversionbatch couponconversionbatch=new couponconversionbatchWapper().selectByBatchCode(createBagCall.getbagCode()).get(0);
			couponconversioncode couponconversioncode=new couponconversioncodeWapper().selectByConversionId(couponconversionbatch.getConversionId()).get(0);
					
			querybagBean.setBagCode(createBagCall.getbagCode());
			querybagBean.setConversionCode(couponconversioncode.getConversionCode());
			querybagBean.setAcquireMethod(2);
			querybagBean.setEffectiveType(0);//有效期类型 0:绝对  1:相对
			querybagBean.setCreateTimeStart(dBefore);
			querybagBean.setCreateTimeEnd(dAfter);
			querybagBean.setApplyDepartment(1);
			querybagBean.setPageIndex(1);
			querybagBean.setPageSize(10);
			
			querybagCall.setData(querybagBean);
			querybagCall.callService();			
			verifyReturn();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private void verifyReturn()
	{
		Logger.verifyEquals("0", querybagCall.getStatusCode1(), "验证返回code");
        Logger.verifyEquals("操作成功！", querybagCall.getMessage(), "验证返回Message");
        querybagBean.setPagesizeStart(0);
        querybagBean.setPagesizeEnd(10);
        List<couponbag> couponbags=new couponbagWapper().selectQueryBag(querybagBean);
        GetBagsByPaging bagsByPaging=querybagCall.getBagInfosReturnData();
        List<BagInfo> bagInfos=bagsByPaging.getBagInfos();
        if(bagsByPaging.getRecordCount()<=querybagBean.getPageSize())
        Logger.verifyEquals(couponbags.size(), bagInfos.size(), "验证返回recordCount与数据库couponbag表中的套券总条数一致");
        querybagBean.setPagesizeStart(-1);
        List<couponbag> counts=new couponbagWapper().selectQueryBag(querybagBean);
        
        Logger.verifyEquals(bagsByPaging.getRecordCount(), counts.size(), "验证返回recordCount套券总条数");
        for(int i=0;i<bagInfos.size();i++)
        {
		 int count=+1;
		 couponbag bag=couponbags.get(i);
		 BagInfo info=bagInfos.get(i);
		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		 
		 Logger.verifyEquals(bag.getBagCode(), info.getBagCode(), "验证返回第"+count+"条bagcode与数据库couponbag表中的bagcode字段一致");
		 Logger.verifyEquals(bag.getAcquireMethod(), info.getAcquireMethod(), "验证返回第"+count+"条acquireMethod与数据库couponbag表中的acquireMethod字段一致");
		 Logger.verifyEquals(bag.getName(), info.getName(), "验证返回第"+count+"条name与数据库couponbag表中的name字段一致");
		 Logger.verifyEquals(bag.getEffectiveType(), info.getEffectiveType(), "验证返回第"+count+"条effectiveType与数据库couponbag表中的effectiveType字段一致");
		 Logger.verifyEquals(sdf.format(bag.getValidStart()), sdf.format(info.getEffectiveStartTime()), "验证返回第"+count+"条effectiveStartTime与数据库couponbag表中的ValidStart字段一致");
		 Logger.verifyEquals(sdf.format(bag.getValidEnd()), sdf.format(info.getEffectiveEndTime()), "验证返回第"+count+"条ValidEnd与数据库couponbag表中的EffectiveEndTime字段一致");
		 Logger.verifyEquals(bag.getEffectiveDays(), info.getEffectiveDays(), "验证返回第"+count+"条effectiveDays与数据库couponbag表中的effectiveDays字段一致");
		 Logger.verifyEquals(bag.getEffectiveValidType(), info.getEffectiveValidType(), "验证返回第"+count+"条effectiveValidType与数据库couponbag表中的effectiveValidType字段一致");
		 
		 Logger.verifyEquals(bag.getTotalAmount().stripTrailingZeros().toPlainString(), info.getTotalAmount().toString(), "验证返回第"+count+"条totalAmount与数据库couponbag表中的totalAmount字段一致");
		 Logger.verifyEquals(bag.getApplyUser(), info.getApplyUser(), "验证返回第"+count+"条ApplyUser与数据库couponbag表中的ApplyUser字段一致");
		 Logger.verifyEquals(sdf.format(bag.getAddTime()), sdf.format(info.getCreateTime()), "验证返回第"+count+"条createTime与数据库couponbag表中的AddTime字段一致");
		 Logger.verifyEquals(bag.getReceiveUserType(), info.getApplyUserType(), "验证返回第"+count+"条applyUserType与数据库couponbag表中的ReceiveUserType字段一致");
		 Logger.verifyEquals(bag.getReceivedCount(), info.getReceivedQuantity(), "验证返回第"+count+"条ReceivedQuantity与数据库couponbag表中的ReceivedCount字段一致");
		 Logger.verifyEquals(bag.getUsePlatformIds(), info.getApplyPlatforms(), "验证返回第"+count+"条ApplyPlatforms与数据库couponbag表中的UsePlatformIds字段一致");
        	 
        }
	}
	
	private void setDefaultPlatformQueryBag() throws ClientProtocolException, IOException
	{
		CouponServiceMCallServiceV2 CouponServiceMCallServiceV2 = new CouponServiceMCallServiceV2();
		CreateBagBean createBagBean = CouponServiceMCallServiceV2.setDefaultPlatformCreateCouponBagBeanForRecieve();
		CreateBagCall createBagCall = CouponServiceMCallServiceV2.createPlatformCouponBag(createBagBean);
		
		Date dNow = new Date(); // 当前时间
        Date dBefore = new Date();
        Date dAfter = new Date();
        
        Calendar calendar1 = Calendar.getInstance(); // 得到日历
        calendar1.setTime(dNow);// 把当前时间赋给日历
        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前10天
        dBefore = calendar1.getTime(); // 得到前10天的时间

        Calendar calendar2 = Calendar.getInstance(); // 得到日历
        calendar2.setTime(dNow);// 把当前时间赋给日历
        calendar2.add(Calendar.DAY_OF_MONTH, 1); // 设置为后2天
        dAfter = calendar2.getTime(); // 得到后2天的时间
        
		querybagBean.setBagCode(createBagCall.getbagCode());
		querybagBean.setConversionCode(null);
		querybagBean.setAcquireMethod(1);
		querybagBean.setEffectiveType(0);//有效期类型 0:绝对  1:相对
		querybagBean.setCreateTimeStart(dBefore);
		querybagBean.setCreateTimeEnd(dAfter);
		querybagBean.setApplyDepartment(1);
		querybagBean.setPageIndex(1);
		querybagBean.setPageSize(10);
	}
}